package com.company.string;

public class primePalindrome {

    public int primePalindrome(int N) {
        int nextPrime = nextPrime(N);
        StringBuilder builder = new StringBuilder(nextPrime);
        while (builder.equals(builder.reverse())) {
            nextPrime = nextPrime(nextPrime);
            builder = new StringBuilder(nextPrime);
        }
        return nextPrime;
    }

    public int nextPrime (int N) {
        int i = N + 1;
        while (true){
            int k = (int)Math.sqrt(i);
            for (int j = 2; j < k; j++) {
                if (i % 2 == 0) {
                    i++;break;
                }
            }
            return i;
        }
    }

}
